﻿using System;
using System.Collections.Generic;
using System.Linq; 
using NTTDATA.BEENChina.ResultCertification.Config;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Address
{
   
    [Serializable]
    [VerfityAttribute(Id = "VerfityA0005", Name = "郡町检证", CategoryType = EnumCategoryType.住所, Model = true)]
    public class VerfityA0005 : VerfityOneResult
    {

    
        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;
            if (result == null)
            {
                return false;
            }

            if (entryCommon == "30" || entryCommon == "20")
            {
                return false;
            }

            foreach (List<string> rowResult in result)
            {

                foreach (string colReulst in rowResult)
                {
                  
                    bresult = CheckPrefectureAndCity(colReulst);

                    if (bresult)
                    {
                        break;
                    }
                }

                if (bresult)
                {
                    break;
                }

            }
            
           

            if (bresult)
            {
               Console.WriteLine("VerfityA0005");
            }

            return bresult;
        }

        /// <summary>
        /// （市栏包含[郡]且不包含[町]，町栏包含[町]时抽出 去掉）
        /// 市栏[郡]结尾，町栏包含[町]时抽出
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        private bool CheckPrefectureAndCity(string result)
        { 

            var splitResult = new Split.SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, result);

            //string prefecture = splitResult.GetPrefecture();
            string city = splitResult.GetCity();
            string town = splitResult.GetTown();

            //&& !city.Contains("町") 
            if (city.EndsWith("郡") && town.Contains("町"))
            {
                return true;
            }
          
            return false;
        }

        
    }
}
